$(function() {
	$("#startDate").datetimepicker({
		format : "yyyy-mm-dd",
		todayBtn : true,
		autoclose : true,
		minView : 2,
		language : "zh-CN"
	}).on("show", function() {
		$("#startDate").datetimepicker("setEndDate", $("#endDate").val());
	})
	$("#endDate").datetimepicker({
		format : "yyyy-mm-dd",
		todayBtn : true,
		autoclose : true,
		minView : 2,
		language : "zh-CN"
	}).on("show", function() {
		$("#endDate").datetimepicker("setStartDate", $("#startDate").val())
	});

	$("#delete").on("hidden.bs.modal", function() {
		$("#msg").text("");
		$("#delEmployment").attr("employmentId", "").attr("studentName", "");
	});
	$("#result").on("hidden.bs.modal", function() {
		$("#response").text("");
	});

	$("#delEmployment").on(
			"click",
			function() {
				id = $(this).attr("employmentId");
				$.ajax({
					data : {
						id : id
					},
					url : "employment/delete",
					type : "get",
					dataType : "json",
					contentType : "application/json",
					success : function(data) {
						$("#delete").modal("hide");
						$("#response").text(data.msg);
						$("#result").modal("show");
						if (data.err == "0") {
							$("button[employmentId=" + id + "]").closest("tr")
									.remove();
						}
					},
					error : function() {
						$("#response").text("系统错误");
						$("#result").modal("show");
					}

				});
			});

	$("button[data-type='export']").click(function() {
		var action = $("form.form-inline").attr("action");
		$("form.form-inline").attr("action", "employment/export");
		$("form.form-inline").submit();
		$("form.form-inline").attr("action", action);
	});

	$("table a").on("click", function() {
		var url = $(this).attr("href");
		var title = $(this).attr("data-title");
		window.parent.tabUtil.add(url, title, true);
		return false;
	});
});

function clearDate(obj) {
	$(obj).closest("span").prev("input").val("");
}

function todel(obj) {
	$("#delEmployment").attr("employmentId", $(obj).attr("employmentId"));
	$("#delEmployment").attr("studentName", $(obj).attr("studentName"));
	$("#msg").text($(obj).attr("studentName") + "的就业信息")
}

function updateEmp(obj) {
	classesValue = $("select[name='classes.product.id']").val();
	educationValue = $("select[name='education.value']").val();
	name = $("input[name='name']").val();
	min = $("input[name='min']").val();
	max = $("input[name='max']").val();
	startDate = $("input[name='startDate']").val();
	endDate = $("input[name='endDate']").val();
	pageNum = $(".pagination li.active a").attr("data-pageNum");
	var pageSize = $("#pageSize").val();
	var url = "employment/toUpdate?id=" + $(obj).attr("employmentId")
			+ "&classes.product.id=" + classesValue + "&education.value="
			+ educationValue + "&name=" + name + "&min=" + min + "&max=" + max
			+ "&startDate=" + startDate + "&endDate=" + endDate + "&pageNum="
			+ pageNum + "&pageSize=" + pageSize;
	var title = $(obj).attr("data-title");
	window.parent.tabUtil.add(url, title, true);

}